'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    /*
      Add altering commands here.
      Return a promise to correctly handle asynchronicity.

      Example:
      return queryInterface.createTable('users', { id: Sequelize.INTEGER });
    */
    const { INTEGER, TINYINT, STRING, DECIMAL, DATE } = Sequelize;
    await queryInterface.createTable('tickets', {
      ticket_id: {
        type: STRING,
        primaryKey: true,
      },
      buyer_id: {
        type: INTEGER,
        allowNull: false,
      },
      start_station: {
        type: STRING,
        allowNull: false,
      },
      end_station: {
        type: STRING,
        allowNull: false,
      },
      go_date: {
        type: STRING,
        allowNull: false,
      },
      go_time: {
        type: STRING,
        allowNull: false,
      },
      amount: {
        type: DECIMAL(8, 2),
        allowNull: false,
      },
      train_num: {
        type: STRING,
        allowNull: false,
      },
      seat_num: {
        type: STRING,
        allowNull: false,
      },
      seat_type: {
        type: STRING,
        allowNull: false,
      },
      ticket_status: {
        type: TINYINT,
        allowNull: false,
        default: 0,
      },
      pay_status: {
        type: TINYINT,
        allowNull: false,
        default: 0,
      },
      created_at: {
        type: DATE,
        allowNull: false,
      },
      updated_at: {
        type: DATE,
        allowNull: false,
      },
    });
  },

  down: async (queryInterface, Sequelize) => {
    /*
      Add reverting commands here.
      Return a promise to correctly handle asynchronicity.

      Example:
      return queryInterface.dropTable('users');
    */
    console.log(Sequelize);
    await queryInterface.dropTable('tickets');
  },
};
